package com.lesserpand.springcloudalibabasso.security.controller;

import com.alibaba.fastjson.JSONObject;
import com.lesserpand.springcloudalibabasso.feign.SecurityOauthFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author bailuo
 * @version 2.0
 * @Description 授权码模式只能浏览器访问认证服务，不能通过服务间调用
 * @Date Created in 2018/12/11 14:40
 */
@RestController
@RequestMapping("/security-oauth")
public class SecurityOauthController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SecurityOauthController.class);

    @Resource
    private SecurityOauthFeign securityOauthFeign;

    /**
     * 密码模式，获取token
     * @param clientId
     * @param secret
     * @return
     */
    @GetMapping("/authorize-password")
    public Object authorizePassword(String userName, String passWord, String clientId, String secret) {
        Object accessTokenBO = securityOauthFeign.getAccessTokenByPassword(userName, passWord);
        LOGGER.info(JSONObject.toJSONString(accessTokenBO));
        return accessTokenBO;
    }

}
